package org.wattdepot.cli.command;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.junit.Test;

/**
 * Test the ListSourcesCommand class.
 * 
 * @author Yichi Xu
 *
 */
public class TestSourcesCommand extends CommandTestBed {

  /**
   * Tests that doCommand method of ListSourcesCommand.
   * 
   * @see org.wattdepot.cli.command.CommandTestBed#testDoCommand()
   */
  @Test
  @Override
  public void testDoCommand() {
    String command;
    String result;
    
    SourcesCommand listCommand = new SourcesCommand(this.client);
    
    //Sad tests
    command = "sources foo";
    result = listCommand.doCommand(command);
    assertTrue("Checking that command is more than one word", 
        result.startsWith(WattDepotCliCommand.PARAMETER_COUNT_ERROR));
    
    //Happy tests
    command = "sources";
    result = listCommand.doCommand(command);
    //make sure it return something that other than the invalid command error message
    assertTrue("Checking that there is word: Parent in the result of list sources command",
        result.contains("Parent"));
    assertFalse("Checking that the command is valid.", 
        result.equals(WattDepotCliCommand.reportUnknownCommand(command)));
    assertFalse("Checking that the connection is fine.",
        result.equals(WattDepotCliCommand.CONNECTION_ERROR));
  }
}
